package com.powernode.controller;

import com.powernode.domain.Area;
import com.powernode.service.AreaService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 内容:
 * 作者: cy
 */
@RestController
@RequestMapping("admin/area")
@Api(tags = "地址管理")
public class AreaController {
    @Autowired
    private AreaService areaService;
    @GetMapping("list")
    @ApiOperation("全查询地址列表")
    @PreAuthorize("hasAuthority('admin:area:list')")
    public ResponseEntity<List<Area>> loadAreaList(){
        List<Area> list = areaService.list();
        return ResponseEntity.ok(list);
    }

    @GetMapping("listByPid")
    @ApiOperation("根据父id查询子区域")
    public ResponseEntity<List<Area>> listByPid(Long pid) {
        List<Area> list = areaService.listByPid(pid);
        return ResponseEntity.ok(list);
    }

}
